package com.jiezhuo.utils;

import com.jiezhuo.entity.cmeduSchool.Jzg;
import com.jiezhuo.entity.cmeduSchool.TJzg;
import com.jiezhuo.entity.cmeduSchool.XxdwXq;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ListUtils {
    public static List<?> subList(List<?> list, int pageSize, int pageNum) {
        int count = list.size(); // 总记录数
        // 计算总页数
        int pages = count % pageSize == 0 ? count / pageSize : count / pageSize + 1;
        // 起始位置
        int start = pageNum <= 0 ? 0 : (pageNum > pages ? (pages - 1) * pageSize : (pageNum - 1) * pageSize);
        // 终止位置
        int end = pageNum <= 0 ? (Math.min(pageSize, count)) : (Math.min(pageSize * pageNum, count));
        return list.subList(start, end);
    }

    public static Map<String, Object> convertMap(List<Map<String, Object>> listMap, String key) {
        Map<String, Object> map = new HashMap<>();
        for (Map<String, Object> objectMap : listMap) {
            map.put(objectMap.get(key).toString(), objectMap);
        }
        return map;
    }

    public static Map<String, TJzg> convertMapToTJzg(List<TJzg> jzgList, String key) {
        Map<String, TJzg> map = new HashMap<>();
        for (TJzg jzg : jzgList) {
            map.put(jzg.getTeacherid(), jzg);
        }
        return map;
    }

    public static Map<String, Object> convertMap(List<Map<String, Object>> listMap, String key, String value) {
        Map<String, Object> map = new HashMap<>();
        for (Map<String, Object> objectMap : listMap) {
            map.put(objectMap.get(key).toString(), objectMap.get(value));
        }
        return map;
    }

    public static Map<String, Object> xqdmListConvertMap(List<XxdwXq> xxdwXqList) {
        Map<String, Object> map = new HashMap<>();
        for (XxdwXq xxdwXq : xxdwXqList) {
            map.put(xxdwXq.getNewXqdm(), xxdwXq.getXqjc());
        }
        return map;
    }
}
